using System;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Collections;
using UnityEditor;
using UnityEngine;
public class MyEditor: EditorWindow
{
    static MyEditor myWindow;
    Vector2 scrollPos;
    [MenuItem("Wb/插件更新")]
    static void Init()
    {
        myWindow = (MyEditor)EditorWindow.GetWindowWithRect(typeof(MyEditor), new Rect(0, 0, 305, 280), true, "WbPackage");
        myWindow.Show();
    }
    void OnGUI()
    {
        EditorGUILayout.LabelField("版本更新记录");
        Startup obj = new Startup();
        string url="http://wbgui.oss-cn-hangzhou.aliyuncs.com/UniWb/wb/config.json";
        string config = obj.GetHttpResponse(url, 6000);
        Record root = JsonUtility.FromJson<Record>(config);

        var log = this.InitContent(root);
        EditorGUILayout.BeginHorizontal();
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(305), GUILayout.Height(225));
        GUILayout.Label(log);
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndHorizontal();

        if (GUI.Button(new Rect (100,255,100,20),"更新插件"))
        {
            obj.ShowDownLoadDialog(root);
        }
    }
    string InitContent(Record root) 
    {
        var content = "";
        for (int i = 0; i < root.record.Count; i++)
        {
            content += "v"+root.record[i].version + "\n";
            content += root.record[i].change + "\n";
            content += root.record[i].date + "\n";
            content += "\n";
        }
        return content;
    }
}